package com.raojunxue.company.action;

import java.util.Date;

import org.apache.struts2.rest.HttpHeaders;

import com.google.appengine.repackaged.org.apache.commons.logging.Log;
import com.google.appengine.repackaged.org.apache.commons.logging.LogFactory;
import com.opensymphony.xwork2.ActionSupport;
import com.raojunxue.company.util.ActionUtil;

public abstract class AbstractAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected static final Log log = LogFactory.getLog(AbstractAction.class);
	
	private String previousUrl;
	
	private String currentUrl;
	
	private String basePath;
	
	private String imagePath;
	
	private Long id;
	
	public abstract HttpHeaders index();

	public abstract HttpHeaders show();

	public abstract HttpHeaders create();

	public abstract HttpHeaders editNew();

	public abstract String update();

	public abstract String edit();

	public abstract String destroy();

	
	public Date getCurrentDate(){
    	return new Date();
    }

	public String getBasePath() {
		return basePath;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}
	
	public String toIndex(){
		return "toIndex";
	}

	public String getPreviousUrl() {
        if(this.previousUrl == null)
            this.previousUrl = ActionUtil.getHttpRequest().getHeader("Referer");
        return previousUrl;
    }

    public void setPreviousUrl(String previousUrl) {
        this.previousUrl = previousUrl;
    }
    
    protected String redirect(){
        ActionUtil.redirect(this.getPreviousUrl());
        return null;
    }
    
    protected String redirectTo(String url){
        ActionUtil.redirect(url);
        return null;
    }

    public String getCurrentUrl() {
        if(this.currentUrl == null){
            this.currentUrl = ActionUtil.getHttpRequest().getRequestURL().toString();
        }
        return this.currentUrl;
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
    
}
